﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using lgweb.common;
using LGCourt.Logic.BLL;
using KMFrame.Core;
using LGCourt.Logic.NBL.DBEntities;
using LGCourt.Logic.Common;

namespace lgweb.inside.office
{
    public partial class notice : NeedValidatePage
    {
        private int _pageIndex = 1;
        private string _Keyword = string.Empty;
        private string dept = string.Empty;
        private string start = string.Empty;
        private string end = string.Empty;
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                this.hdOADomain.Value = System.Configuration.ConfigurationManager.AppSettings["OADomain"];
                GetParam();
                GetDepartmentList();
                GetList();                
            }
        }

        private void GetParam()
        {
            this._Keyword = string.IsNullOrEmpty(Request.QueryString["Keyword"]) ? "" : Request.QueryString["Keyword"];
            this._pageIndex = string.IsNullOrEmpty(Request.QueryString["PageIndex"]) ? 1 : Convert.ToInt32(Request.QueryString["PageIndex"]);
            this.dept = string.IsNullOrEmpty(Request.QueryString["dept"]) ? "" : Request.QueryString["dept"];
            this.start = string.IsNullOrEmpty(Request.QueryString["start"]) ? "" : Request.QueryString["start"];
            this.end = string.IsNullOrEmpty(Request.QueryString["end"]) ? "" : Request.QueryString["end"];
            this.txtKeyword.Value = _Keyword;
        }
        //绑定部门
        private void GetDepartmentList()
        {
            DepartmentHandler bll = new DepartmentHandler();
            List<Department> result = (List<Department>)bll.GetDepartmentList();
            if (result != null && result.Count > 0)
            {
                Department PleaseLocation = new Department();
                PleaseLocation.Code = "0";
                PleaseLocation.Name = "选择部门";
                result.Insert(0, PleaseLocation);
                this.sltDepartment.DataSource = result;
                this.sltDepartment.DataTextField = "Name";
                this.sltDepartment.DataValueField = "Name";
                this.sltDepartment.DataBind();                
            }
            this.sltDepartment.Value = this.dept;
            this.txtKeyword.Value = _Keyword;
            this.txtStartDate.Value = start;
            this.txtEndDate.Value = end;
        }
        private void GetList()
        {
            OA bll = new OA();
            OANoticeCondition param = new OANoticeCondition();
            param.UserID = this.SessionInfo.UserID;
            param.PageSize = 20;
            param.PageIndex = this._pageIndex;
            param.Keyword = _Keyword;
            if (!string.IsNullOrEmpty(this.start))
            {
                param.BeginDate = DateTime.Parse(this.start);
            }
            if (!string.IsNullOrEmpty(this.end))
            {
                param.EndDate = DateTime.Parse(this.end);
            }
            param.DeptName = dept;
            PageResult result = (PageResult)bll.GetTongzhiGonggaoPage(param);

            if (result != null && result.ResultList!=null)
            {
                this.rptNoticeList.DataSource = (List<vOATongzhiGonggao>)result.ResultList;
                this.rptNoticeList.DataBind();
                this.pager1.RecordCount = result.TotalCount;
                this.pager1.TotalPage = result.PageCount;
                this.pager1.PageIndex = this._pageIndex;
                this.pager1.PageSize = 20;
                this.pager1.LinkUrl = string.Format("/inside/office/notice.aspx?Keyword={0}&PageIndex={1}&dept={2}&start={3}&end={4}", Server.UrlEncode(this._Keyword), this._pageIndex, this.dept, this.start, this.end);
            }
        }
    }
}